package src; 

import java.awt.Color;
import java.util.ArrayList;
import java.util.Random;

/**
 * A very rudimentary Computer AI. Simply finds open moves and picks a random one. 
 * @author Arjun
 */
public class ComputerPlayer extends Player
{

    public ComputerPlayer( Color c )
    {
        super(c);
    }

    /** 
     * Gets a list of all the empty and possible moves (depending on Current Sub Grid) and 
     * randomly selects where to move. 
     */
    @Override
    public GridLocation getPlay()
    {
    	
    	ArrayList<GridLocation> moves;
        if( game.getCurrentSubGrid() == null )
        {
        	moves = game.getBoard().getAllOpenLocations(); 
        }
        else
        {
        	moves = game.getCurrentSubGrid().getOpenLocations(); 
        }
        
        if( moves.size() != 0 )
        {
        	Random rand = new Random(); 
            GridLocation loc = moves.get( rand.nextInt(moves.size()) );
            game.moveMade(loc);
            return loc;
        }
        else
        {
        	return null; 
        }
        

    }

    /** 
     * Taken care of in getPlay() - Player.play() never calls setPlay(); 
     */
    public void setPlay( GridLocation loc )
    {
    	//unimplemented
    }

	@Override
	public String toString() 
	{
		return "Computer"; 
	}

}
